using System;
using System.Windows.Forms;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using Habanero.Base;
using Habanero.BO;
using Habanero.BO.ClassDefinition;
using Habanero.Faces.Base;
using Habanero.Faces.Win;

namespace FireStarterModeller.UI.ViewEditor
{
    public class UIPreviewControl : UserControlWin, IUIPreviewControl
    {

        public IReadOnlyGridControl GridControl { get; private set; }
        public IPanelInfo FormPanelInfo { get; private set; }

        private readonly IControlFactory _controlFactory;
        public UIPreviewControl(IControlFactory controlFactory) { _controlFactory = controlFactory; }
       
        public void PreviewGrid(IClassDef classDef, IUIGrid gridDef) {
            GridControl = _controlFactory.CreateReadOnlyGridControl();
            GridControl.Initialise(classDef, gridDef, "");
            this.Controls.Clear();
           // GridControl.BusinessObjectCollection = Broker.GetBusinessObjectCollection(classDef,"");
            BorderLayoutManager manager = _controlFactory.CreateBorderLayoutManager(this);
            manager.AddControl(GridControl, BorderLayoutManager.Position.Centre);
        }

        public void PreviewForm(IClassDef classDef, IUIForm formDef) { 
            PanelBuilder builder = new PanelBuilder(_controlFactory);
            FormPanelInfo = builder.BuildPanelForForm(formDef);
            FormPanelInfo.BusinessObject = new Entity(classDef);
            this.Controls.Clear();
            IPanel panel = FormPanelInfo.Panel;
            PanelWin containerPanel = (PanelWin) _controlFactory.CreatePanel();
            containerPanel.Left = 0;
            containerPanel.Top = 0;
            containerPanel.Height = FormPanelInfo.UIForm.Height;
            containerPanel.Width = FormPanelInfo.UIForm.Width;
            containerPanel.BorderStyle = BorderStyle.FixedSingle;
            containerPanel.Controls.Add((Control) panel);
            this.Controls.Add(containerPanel);
        }
    }
}